require(["config"],function(){
	require(["jquery","header","cookie"],function($){
		function Login(){
			this.addListener();
		}
		$.extend(Login.prototype,{
			addListener: function() {
				$("form").on("submit", $.proxy(this.loginHandler, this));
			},
			loginHandler:function(){
				var data = $("form").serialize();
				console.log(data);
				var url = "http://localhost/api/login.php";
				$.post(url, data, this.loginSuccessHandler, "json");
				return false;
			},
			loginSuccessHandler:function(data){
				if (data.res_code === 1) {
					$.cookie.json = true;
					$.cookie("login-user", data.res_body, {path: "/"});
					// 跳转页面
					window.location = "/";
				} else { // 登录失败
					$(".reg-tip").html("账号或密码不正确，请重新输入！");
				}

			}
		});
		new Login();
	});
});